#include <stdio.h>
#include <fcntl.h>
#include <errno.h>


int main (int argc, char *argv[])
{
    int fd, ret, i;
    int press_count[4] = { 0 };

    fd = open("/dev/mybuttons", O_RDONLY);
    if (fd < 0) {
        printf("open /dev/mybuttons error, errno=%d\n", errno);
        return -1;
    }

    while (1) {
        ret = read(fd, press_count, sizeof(press_count));
        if (ret < 0) {
            perror("read error");
            break;
        }

        for (i = 0; i < sizeof(press_count) / sizeof(press_count[0]); i++) {
            printf("button %d has been pressed %d times\n", i, press_count[i]);
        }
    }

    return 0;
}
